<?php

declare(strict_types=1);

namespace app\common\model\im;

use think\Model;
use app\common\traits\ModelTrait;

/**
 * 聊天群组用户关联-模型
 * @author:kaige
 * @update:2022-06-12
 * @copyright ©2022 泉州市盛筑信息科技有限公司 版权所有
 */
class ImGroupUser extends Model
{
  //开启自动写入时间戳字段
  protected $autoWriteTimestamp = true;
  protected $createTime = 'create_time';
  protected $updateTime = null;

  // 设置字段信息(避免多一次查询的开销)
  protected $schema = [
    'id'            => 'int',
    'group_id'      => 'int',
    'uid'           => 'int',
    'nickname'      => 'string',
    'sign'          => 'string',
    'memo'          => 'string',
    'is_top'        => 'int',
    'is_show_nick'  => 'int',
    'chat_bg'       => 'string',
    'create_time'   => 'int'
  ];

  use ModelTrait;

  //关联用户
  public function gluser()
  {
    return $this->hasOne('\app\common\model\sys\SysUser', 'id', 'uid');
  }

  //关联组
  public function glgroup()
  {
    return $this->hasOne('\app\common\model\im\ImGroup', 'id', 'group_id')->bind(['group_name' => 'name','avatar'=>'chat_head']);
  }

 
}
